﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Gift.DAL;
using Gift.Model;
using Gift.Model.crm;
using Gift.DAL.crm;
using Gift.Model.crm.eNum;

namespace WebSite.crm.admin
{
    public partial class adminManager : BaseCrm
    {
        readonly adminlogin theAdminLogin = new adminlogin();
        DB_adminlogin oAdminLogin;
        readonly MemberAccount theMemberAccount = new MemberAccount();
        // Methods
        private void DeletedAdmin()
        {

            if ((base.Request.QueryString["uid"] != null) && (base.Request.QueryString["action"] != null))
            {
                oAdminLogin = theAdminLogin.GetModel(int.Parse(base.Request.QueryString["uid"].ToString()));
                oAdminLogin.IsDeleted = true;
                theAdminLogin.Update(oAdminLogin);
                ExtAspNet.Alert.Show("删除管理员成功！");
                this.BindGrid();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.ValidateLoginRule(eRule.AdminManager);
                this.DeletedAdmin();
                this.BindGrid();
            }
        }


        protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
        }

        string GetSqlWhere
        {
            get
            {
                StringBuilder strWhere = new StringBuilder();

            
                    strWhere.Append(" and isnull(a.AdminTypeId,0) = 5  ");

                return strWhere.ToString();
            }
        }


        protected void Grid1_Sort(object sender, ExtAspNet.GridSortEventArgs e)
        {
            DataTable table = theAdminLogin.GetAdminList(GetSqlWhere).Tables[0];
            DataView view1 = table.DefaultView;
            view1.Sort = String.Format("{0} {1}", e.SortField, e.SortDirection);
            Grid1.DataSource = view1;
            Grid1.DataBind();
        }
        private void BindGrid()
        {
            DataTable table = theAdminLogin.GetAdminList(GetSqlWhere).Tables[0];
            Grid1.DataSource = table;
            Grid1.DataBind();

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.BindGrid();
        }
    }
}